import java.lang.management.MemoryManagerMXBean;
import java.util.Scanner;
import java.util.Stack;

public class DAY0514 {
    public static void main(String[] args) {
        Scanner s =new Scanner(System.in);
        int X = s.nextInt();
        int[] fibnq = new int[1000000];
        fibnq[0] = 0;
        fibnq[1] = 1;
        int i = 0;
        for (i = 2; i < X ; i++) {
            fibnq[i] = fibnq[i-1] + fibnq[i-2];
            if (fibnq[i] > X){
                break;
            }
        }

        int num = Math.min(Math.abs(fibnq[i]-X), Math.abs(fibnq[i-1]-X));
        System.out.println(num);

    }

    public boolean chkParenthesis(String A, int n) {
        // write code here

        Stack<Character> stack = new Stack<Character>();
        //判断条件
        if(A == null || A.length() != n){
            return false;
        }
        for(int i = 0;i < A.length();i++){
            //左括号  入栈
            if(A.charAt(i) == '('){
                stack.push(A.charAt(i));
            }else if(A.charAt(i) == ')'){
                //右括号匹配 匹配不到为false 匹配到出栈
                if(stack.empty()){
                    return false;
                }else{
                    stack.pop();
                }
            }else{
                return false;
            }
        }
        //判断栈是否为空，为空表示全部匹配完
        if(!stack.empty()){
            return false;
        }else {
            return true;
        }
    }
}
